# I2C Scanner MicroPython
from machine import SoftI2C
from lib.sensors.ssd1306.oled import OLED
from lib.config.index import sensor_config

"""
framebuf显示
支持常见的ascii可见字符
8X8
"""

config = sensor_config.get_sensor("ssd1306")
# print(config)
scl = config["scl"]
sda = config["sda"]

i2c = SoftI2C(scl, sda)

print("I2C SCANNER")
devices = i2c.scan()

if len(devices) == 0:
    print("No i2c device !")
else:
    print("i2c devices found:", len(devices))

    for device in devices:
        print("I2C hexadecimal address: ", hex(device))


def demo():
    text = "12345"
    _oled = OLED(scl, sda)
    _oled.clear()
    _oled.text(text, 0, 0)
    _oled.show()


if __name__ == "__main__":
    demo()
